/*	File name: 		TIADEM.h
 * 	Authors:		Peter Christiansen & Mads Dyrmann Larsen
 * 	Purpose:		This is the header file for exam project in TIADEM 
 * 					autumn 2012.
 */

#ifndef TPSN2_H
#define TPSN2_H

//#define USEPRINTF
#define NUMBERSPRINTF

// Number of Trails to send SyncPulse and receive ACK.
#define nTrialsMax 4

#define msg_StartSync 0
#define msg_SyncPuls 1
#define msg_Ack 2
#define msg_LevelRequest 3
#define msg_AckLevelRequest 4
#define msg_LevelDisc 11

#define SSM_BaseState	1
#define SSM_WaitState	2
#define SSM_BackOffState	3
#define SSM_SendSyncPulseState	4
#define SSM_SynchronizeNodeState	5
#define SSM_SendAckState	6
#define SSM_RootStartResyncState	7
#define SSM_AckReceivedState 8
#define SSM_LevelReqState 9
#define SSM_RxLevelReqState 10

// new
#define SSM_Mode5_LevelReqState 11



enum {
  AM_PROJECT1 = 0x93,	// This is important for read out on scope!!!
  AM_SERIAL_MSG = 0x89,
};

// Our struct for syncronization payload over radio:
typedef nx_struct RadioMsg {
  nx_uint8_t messageType; 
  nx_uint8_t nodeTreeLevel;
  nx_uint16_t senderID;
  nx_int32_t T2;
  nx_int32_t T3;
} RadioMsg;

typedef nx_struct syncInfo1_t {
  nx_uint16_t senderID;
  nx_int32_t T2;
  nx_int32_t T3;
} syncInfo1_t;

typedef nx_struct syncInfo2_t {
  nx_int32_t T1;
  nx_int32_t T2;
  nx_int32_t T3;
  nx_int32_t T4;
} syncInfo2_t;


typedef nx_struct serial_msg {
  nx_uint32_t data1;
  nx_uint32_t data2;
  nx_uint32_t data3;
  nx_uint32_t data4;
  nx_uint32_t data5;
  nx_uint32_t data6;  
} serial_msg_t;


typedef nx_struct rx_serial_msg {
  nx_uint8_t cmd;
} rx_serial_msg_t;


#endif /* TPSN2_H */

/* 
 	_________________________________________
	|_PHR_|_______MHR_______|__MPL__|__MFR__|
	|__1__|__2__|__1__|__8__|__12___|___2___|
	|_________________FIFO__________________|
	|_________________128___________________|
	PHR - Frame Length without this byte.
	MHR - MAC Header: Frame Control Field[2] + Data Sequence Number[1] + Address Information[8]
	MPL - MAC Payload: Contains the generic Frame Payload (Between 10 and 16 bytes)
	MFR - MAC Footer: Contains Frame Check Sequence

 */